home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * AllocP - supply a better AllocMem/AllocVec *
- * *
- * written by Andreas R. Kleinert *
- * Andreas_Kleinert@t-online.de *
- * *
- * No Assembler - 100 percent C *
- * *
- * V1.0 : *
- * - first release *
- * *
- ************************************************************************/
-
- #define __USE_SYSBASE
-
- #include <exec/execbase.h>
- #include <exec/memory.h>
- #include <intuition/intuitionbase.h>
- #include <libraries/gadtools.h>
-
- #include <string.h>
- #include <stdio.h>
-
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/intuition.h>
- #include <proto/utility.h>
-
- #define N (NULL)
-
-
- extern struct ExecBase *SysBase;
-
- struct IntuitionBase *IntuitionBase = N;
-
-
- APTR __far NewAllocMemVec;
- ULONG __far __asm (*OrigAllocMemVec)(register __d0 ULONG size,
- register __d1 ULONG memf,
- register __a6 struct ExecBase *ExecBase_a6);
-
- APTR __far NewAllocVecVec;
- ULONG __far __asm (*OrigAllocVecVec)(register __d0 ULONG size,
- register __d1 ULONG memf,
- register __a6 struct ExecBase *ExecBase_a6);
-
-
- ULONG __asm NewAllocMem(register __d0 ULONG size,
- register __d1 ULONG memf,
- register __a6 struct ExecBase *ExecBase_a6)
- {
- ULONG ptr;
-
- ptr = OrigAllocMemVec(size, memf, ExecBase_a6);
- if(!ptr)
- {
- OrigAllocMemVec(0xFFFFFFFF, MEMF_ANY, ExecBase_a6);
-
- ptr = OrigAllocMemVec(size, memf, ExecBase_a6);
- }
-
- return((ULONG) ptr);
- }
-
- ULONG __asm NewAllocVec(register __d0 ULONG size,
- register __d1 ULONG memf,
- register __a6 struct ExecBase *ExecBase_a6)
- {
- ULONG ptr, nsize;
-
-
- nsize = size + (size & 3); /* avoid alignment gaps */
-
- ptr = OrigAllocVecVec(nsize, memf, ExecBase_a6);
- if(!ptr)
- {
- OrigAllocVecVec(0xFFFFFFFF, MEMF_ANY, ExecBase_a6);
-
- ptr = OrigAllocVecVec(nsize, memf, ExecBase_a6);
- }
-
- return((ULONG) ptr);
- }
-
- /* *************************************************** */
- /* * * */
- /* * Compiler Stuff for BackgroundIO * */
- /* * * */
- /* *************************************************** */
-
- long __stack = 8192;
- char *__procname = "AllocP";
- long __priority = 1;
- long __BackGroundIO = 1; /* TRUE : We DO BackGroundIO ! */
-
- extern BPTR _Backstdout; /* NULL, if started from Workbench */
-
- void __regargs __chkabort(void) { }
- void __regargs _CXBRK(void) { }
-
- char vertext [] = "\0$VER: AllocP V1.0";
-
-
- typedef unsigned long (*FUNCCAST)();
-
- long main(long argc, char **argv)
- {
- long retval = 0;
-
- APTR task;
-
- Forbid();
- task = FindTask(N);
- Permit();
-
- if(task) SetTaskPri(task, __priority);
-
-
- IntuitionBase = (APTR) OpenLibrary("intuition.library", 39);
- if(IntuitionBase)
- {
- UtilityBase = (APTR) OpenLibrary("utility.library", 37);
- if(UtilityBase)
- {
- OrigAllocMemVec = (long (* __asm )(register __d0 ULONG size,
- register __d1 ULONG memf,
- register __a6 struct ExecBase *ExecBase_a6)) SetFunction((APTR)SysBase, -0xc6, (APTR)NewAllocMem);
-
- OrigAllocVecVec = (long (* __asm )(register __d0 ULONG size,
- register __d1 ULONG memf,
- register __a6 struct ExecBase *ExecBase_a6)) SetFunction((APTR)SysBase, -0x2ac, (APTR)NewAllocVec);
-
- if(OrigAllocMemVec || OrigAllocVecVec)
- {
- if(task) SetTaskPri(task, -10);
- Wait(SIGBREAKF_CTRL_C);
- if(task) SetTaskPri(task, 1);
-
- NewAllocMemVec= (APTR) SetFunction((APTR)SysBase, -0xc6, (APTR)OrigAllocMemVec);
- NewAllocVecVec= (APTR) SetFunction((APTR)SysBase, -0x2ac, (APTR)OrigAllocVecVec);
-
- if(NewAllocMemVec!=NewAllocMem)
- {
- ULONG idcmp = N;
- struct EasyStruct estr;
-
- estr.es_StructSize = sizeof(struct EasyStruct);
- estr.es_Flags = N;
- estr.es_Title = "AllocP Request";
- estr.es_TextFormat = "Error while removing from system !\n"
- "There were more patches !"
- "Do a reset soon !";
- estr.es_GadgetFormat = "Ok";
-
- EasyRequestArgs(N, &estr, (ULONG *) &idcmp, N);
- }
-
- if(NewAllocVecVec!=NewAllocVec)
- {
- ULONG idcmp = N;
- struct EasyStruct estr;
-
- estr.es_StructSize = sizeof(struct EasyStruct);
- estr.es_Flags = N;
- estr.es_Title = "AllocP Request";
- estr.es_TextFormat = "Error while removing from system !\n"
- "There were more patches !"
- "Do a reset soon !";
- estr.es_GadgetFormat = "Ok";
-
- EasyRequestArgs(N, &estr, (ULONG *) &idcmp, N);
- }
-
- }else retval = 20;
-
- CloseLibrary((struct Library *) UtilityBase);
-
- }else retval = 20;
-
- CloseLibrary((struct Library *) IntuitionBase);
-
- }else retval = 20;
-
- return(retval);
- }
-